<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    //1.封装函数
    function getArrSum(arr = []) {
      let sum = 0
      for (let i = 0; i < arr.length; i++) {
        sum += arr[i]
      }
      console.log(sum)
    }
    getArrSum([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
    getArrSum([11, 22, 33])
    getArrSum()

    // function getArrSum1(arr) {
    //   let sum = 0
    //   for (let i = 0; i < arr.length; i++) {
    //     sum += arr[i]
    //   }
    //   console.log(sum)
    // }
    // getArrSum1() arr没有赋值是undefined,arr.length即是undefined.length会报错
  </script>
</body>

</html>